package br.com.fip.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;

import br.com.fip.model.Notificacao;
import br.com.fip.util.Log;

public class NotificacaoDAO {
	
	private Session session;
	
	public void adicionarNotificacao(Notificacao notificacao, Session session){
		this.session = session;
		try{
			this.session.beginTransaction();
			this.session.save(notificacao);
			this.session.getTransaction().commit();
		}catch(IllegalArgumentException e){
			e.printStackTrace();
			Log.getLogger().error(e);
		}
	}
	
	public void excluirNotificacao(Notificacao notificacao, Session session){
		this.session = session;
		try{
			this.session.beginTransaction();
			this.session.delete(notificacao);
			this.session.getTransaction().commit();
		}catch(IllegalArgumentException e){
			e.printStackTrace();
			Log.getLogger().error(e);
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<Notificacao> listarNotificacoes(Session session){
		this.session = session;
		try{
			Criteria criteria = this.session.createCriteria(Notificacao.class);
			return criteria.list();
		}catch(IllegalArgumentException e){
			e.printStackTrace();
			Log.getLogger().error(e);
		}
		
		return null;
	}

}
